Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libexpr: deprecate the bogus "or"-as-variable #11560

Merged
merged 1 commit into from
Oct 2, 2024

Conversation

rhendric
Copy link
Member

Motivation

As a prelude to making or work like a normal variable, emit a warning any time the fn or production is used in a context that will change how it is parsed when that production is refactored.

In detail: in the future, OR_KW will be moved to expr_simple, and the cursed ExprCall production that is currently part of the expr_select nonterminal will be generated "normally" in expr_app instead. Any productions that accept an expr_select will be affected, except for the expr_app nonterminal itself (because, while expr_app has a production accepting a bare expr_select, its other production will continue to accept fn or expressions). So all we need to do is emit an appropriate warning when an expr_simple representing a cursed ExprCall is accepted in one of those productions without first going through expr_app.

As the warning message describes, users can suppress the warning by wrapping their problematic fn or expressions in parentheses. For example, f g or can be made future-proof by rewriting it as f (g or); similarly [ x y or ] can be rewritten as [ x (y or) ], etc. The parentheses preserve the current grouping behavior, as in the future f g or will be parsed as (f g) or, just like f g anything-else is grouped. (Mechanically, this suppresses the warning because the problem ExprCalls go through the expr_app : expr_select production, which resets the cursed status on the ExprCall.)

Context

Forked from #11121, which will be rebased atop this once it is merged and then sit around for however many years it's decided is an appropriate deprecation period.

Priorities and Process

Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

As a prelude to making "or" work like a normal variable, emit a warning
any time the "fn or" production is used in a context that will change
how it is parsed when that production is refactored.

In detail: in the future, OR_KW will be moved to expr_simple, and the
cursed ExprCall production that is currently part of the expr_select
nonterminal will be generated "normally" in expr_app instead. Any
productions that accept an expr_select will be affected, except for the
expr_app nonterminal itself (because, while expr_app has a production
accepting a bare expr_select, its other production will continue to
accept "fn or" expressions). So all we need to do is emit an appropriate
warning when an expr_simple representing a cursed ExprCall is accepted
in one of those productions without first going through expr_app.

As the warning message describes, users can suppress the warning by
wrapping their problematic "fn or" expressions in parentheses. For
example, "f g or" can be made future-proof by rewriting it as
"f (g or)"; similarly "[ x y or ]" can be rewritten as "[ x (y or) ]",
etc. The parentheses preserve the current grouping behavior, as in the
future "f g or" will be parsed as "(f g) or", just like
"f g anything-else" is grouped. (Mechanically, this suppresses the
warning because the problem ExprCalls go through the
"expr_app : expr_select" production, which resets the cursed status on
the ExprCall.)
@rhendric rhendric requested a review from edolstra as a code owner September 20, 2024 20:28
@github-actions github-actions bot added the with-tests Issues related to testing. PRs with tests have some priority label Sep 20, 2024
@edolstra
Copy link
Member

Realistically, the special or handling can never be removed since we don't want to kill the ability to evaluate old projects. (At least not until we have a way to version the language, like Rust's "edition" field.)

@rhendric
Copy link
Member Author

This is an implementation of #11121 (comment), not a prelude to removing support for or as a variable altogether.

@tomberek tomberek added the idea approved The given proposal has been discussed and approved by the Nix team. An implementation is welcome. label Sep 30, 2024
@Mic92
Copy link
Member

Mic92 commented Sep 30, 2024

So we discussed this in the team meeting. We just want to make sure our flake regression suite passes without too many warnings:

https://github.com/NixOS/flake-regressions/

Otherwise we need @edolstra for code review.

@rhendric
Copy link
Member Author

Are you asking me to do the flake regression test, or just updating on status?

@tomberek
Copy link
Contributor

Are you asking me to do the flake regression test, or just updating on status?

It was informative because I think Eelco was going to run it, but it helps if you can. Plus it helps to have more people familiar with it.

@rhendric
Copy link
Member Author

rhendric commented Oct 1, 2024

Attempting to do so, it appears that the directory added in NixOS/flake-regressions-data@c73996a is not at the level of nesting expected by the eval-all.sh script. Could be user error though.

@rhendric
Copy link
Member Author

rhendric commented Oct 2, 2024

Well, I've evaluated every flake in the regression suite, and while not every test passed, there are no occurrences of the new warning (as should be expected).

@Mic92
Copy link
Member

Mic92 commented Oct 2, 2024

Sounds good to me than.

@edolstra edolstra merged commit f5a2f2a into NixOS:master Oct 2, 2024
11 checks passed
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2024-09-30-nix-team-meeting-minutes-182/53814/1

@rhendric rhendric deleted the rhendric/deprecate-cursed-or branch October 2, 2024 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
idea approved The given proposal has been discussed and approved by the Nix team. An implementation is welcome. with-tests Issues related to testing. PRs with tests have some priority
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants